package cn.tedu.tmall.admin.content.controller;

import cn.tedu.tmall.admin.content.pojo.param.CategoryAddParam;
import cn.tedu.tmall.admin.content.service.ICategoryService;
import cn.tedu.tmall.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 管理端分类管理相关接口
 */
@RestController
@Api(tags = "管理端类别相关接口")
@Slf4j
@RequestMapping("/category")
public class CategoryController {

    //    @Resource (name = "ACategoryService")
    //@Autowired 和 @Resource都能加载,都加载的是CategoryService
    @Resource
    private ICategoryService categoryService;

    /**
     * 增加分类
     * @param categoryAddParam 分类详情
     * @return
     */
    @ApiOperation("增加类别")
    @PostMapping("/add")
    public JsonResult addCategory(@Validated @RequestBody CategoryAddParam categoryAddParam) {

        //快速失败,
        //1 验证入参
        // 1 分类名称不能为空
        // 2 分类名称的长度不能超过4个
        // 上面的验证逻辑应该写在哪?
        //   1 controller
        //   2
        System.out.println(categoryService);
        log.debug("增加分类接口入参:{}", categoryAddParam);
        categoryService.addCategory(categoryAddParam);
        JsonResult ok = JsonResult.ok();
        log.debug("增加分类接口入参:{},出参:{}",categoryAddParam,ok);
        return ok;

    }
}
